<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        // 字符串替换
        // const hd = "baidu.com";
        // console.log(hd.replace("baidu", "wfj"));

        const word = ["php", "css"];
        const str = "学习了php和css";
        const strReplace = word.reduce((pre, word) => pre.replace(word, `<a href="?w=${word}">${word}</a>`), str);
        console.log(strReplace);
        document.body.innerHTML += strReplace;
    </script>
</body>

</html>